﻿///<reference path="/ScriptsG/ContactManagerDynamic.js" />
///<reference path="/Scripts/JQuery/jquery-1.8.3-vsdoc.js" />
///<reference path="/Scripts/Views/_Layout.js" />
///<reference path="/Scripts/KendoUI/kendo.web.js" />
//INNOVACALL FRAMEWORK MUST BE IN ALL VIEW JAVASCRIPT

/// dataSource will be used by kendo web ui data grid
var dataSource;
var communityManagerMap;

$.fn.DocReady = function () {
    $.fn.PrepareLayoutMenus();
    $.fn.ConfigureGoogleMap();
    $.fn.ConfigureGrid();
    $.fn.ConfigureTabs();
    //Kendo ui bug grid sizing fixup
    $(".k-grid-content").css("height", "387px");
}

$.fn.ConfigureTabs = function () {
    $("#divTabs").tabs();
}

$.fn.ConfigureGoogleMap = function () {
    var mapOptions = {
        zoom: 2,
        center: new google.maps.LatLng(46.52863469527167, 2.43896484375),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var container = document.getElementById('divGoogleMap');
    var communityManagerMap = new google.maps.Map(container, mapOptions);
    $.fn.GoogleMapAddMultipleUserMarkers(communityManagerMap,MemberLocations);
}

$.fn.ConfigureDataSource = function () {
    toReturn = new kendo.data.DataSource({
        type: "odata",
        transport: {
            read: {
                url: "/odata/contacts",
                dataType: "json"
            }
        },
        schema: {
            data: function (data) {
                return data["value"];
            },
            total: function (data) {
                return data["odata.count"];
            },
            model: {
                fields: {
                    ContactId: { type: "number" },
                    UserId: { type: "number" },
                    Genre: { type: "string" },
                    FirstName: { type: "string" },
                    LastName: { type: "string" },
                    Username: { type: "string" },
                    Town: { type: "string" },
                    Country: { type: "string" },
                    EMail: { type: "string" }
                }
            }
        },
        pageSize: 12,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true
    });
    return toReturn;
}

$.fn.ConfigureGrid = function () {
    $("#divGrid").kendoGrid({
        dataSource: $.fn.ConfigureDataSource(),
        filterable: true,
        sortable: true,
        height: 450,
        pageable: { messages: { display: "{0:d0} - {1:d0} " + cap_KendoUIGrid_Pageable_Of + " {2:d0} " + cap_KendoUIGrid_Pageable_Elements } },
        columns: [
            {
                field: "ContactId",
                filterable: false,
                hidden: true
            },
            {
                field: "UserId",
                filterable: false,
                hidden: true
            },
            {
                field: "Genre",
                title: cap_ContactManager_GridColumn_Genre,
                width: 55
            },
            {
                field: "FirstName",
                title: cap_ContactManager_GridColumn_FirstName,
                width: 90
            },
            {
                field: "LastName",
                title: cap_ContactManager_GridColumn_LastName,
                width: 90
            },
            {
                field: "Username",
                title: cap_ContactManager_GridColumn_Username,
                width: 90
            },
            {
                field: "Town",
                title: cap_ContactManager_GridColumn_Town,
                width: 90
            },
            {
                field: "Country",
                title: cap_ContactManager_GridColumn_Country,
                width: 90
            },
            {
                field: "EMail",
                title: cap_ContactManager_GridColumn_EMail,
                width: 120
            }
        ]
    });
}